package init

import (
	"github.com/nacos-group/nacos-sdk-go/clients"
	"github.com/nacos-group/nacos-sdk-go/common/constant"
	"github.com/nacos-group/nacos-sdk-go/vo"
	"log"
	"video-service/basic/config"
)

func InitNacos() {
	//create clientConfig
	clientConfig := constant.ClientConfig{
		NamespaceId:         config.AppConfi.Nacos.PubicId, //we can create multiple clients with different namespaceId to support multiple namespace.When namespace is public, fill in the blank string here.
		TimeoutMs:           5000,
		NotLoadCacheAtStart: true,
		LogDir:              "/tmp/nacos/log",
		CacheDir:            "/tmp/nacos/cache",
		LogLevel:            "debug",
	}
	// At least one ServerConfig
	serverConfigs := []constant.ServerConfig{
		{
			IpAddr:      config.AppConfi.Nacos.Host,
			ContextPath: "/nacos",
			Port:        uint64(config.AppConfi.Nacos.Port),
			Scheme:      "http",
		},
	}
	// Create config client for dynamic configuration
	configClient, _ := clients.CreateConfigClient(map[string]interface{}{
		"serverConfigs": serverConfigs,
		"clientConfig":  clientConfig,
	})
	content, _ := configClient.GetConfig(vo.ConfigParam{
		DataId: config.AppConfi.Nacos.DataId,
		Group:  config.AppConfi.Nacos.Group})
	log.Println("nacos 连接成功")
	log.Println(content)
}
